package chapter10;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/18 19:31
 */
public class TreeMapTest {
    public static void main(String[] args) {
        List<String> list = new LinkedList<>();

        Map<String, String> map = new TreeMap<>();
        map.put("a", "abstract");
        map.put("c", "call");
        map.put("b", "basic");
        map.put("T", "tree");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
        System.out.println("---------------------------------");

        Map<String, String> map1 = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        map1.put("a", "abstract");
        map1.put("c", "call");
        map1.put("b", "basic");
        map1.put("T", "tree");
        map1.put("t", "try");
        for (Map.Entry<String, String> entry : map1.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
        System.out.println("----------------------------");

        Map<String, String> map2 = new TreeMap<>(Comparator.reverseOrder());
        map2.put("a", "abstract");
        map2.put("c", "call");
        map2.put("b", "basic");
        map2.put("T", "tree");
        for (Map.Entry<String, String> entry : map2.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }

        Map<String, Integer> map3 = new TreeMap<>((o1, o2) -> {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            try {
                return format.parse(o1).compareTo(format.parse(o2));
            } catch (ParseException e) {
                e.printStackTrace();
                return 0;
            }
        });

        map3.put("2016-7-3", 100);
        map3.put("2016-7-10", 100);
        map3.put("2016-8-3", 100);

        map3.forEach((key, value) -> System.out.println(key + "," + value));
    }
}
